--[[
	处理使用道具
]]
local filename = "uploadscore.lua"

local timetool = require "timetool"
local skynet = require "skynet"
local cluster = require "skynet.cluster"
local filelog =require "filelog"
local redisdao = require "redisdao"
require "pubenum"

local json = require "cjson"
json.encode_sparse_array(true,1,1)


local service = nil
local CMD = {
	service = nil
}

--小游戏列表
-- dds 打地鼠 dfj 打飞机 llk连连看
local gamelist = { dds = true, dfj = true, llk = true}

--
--上传小游戏分数
--
function CMD.process(rid, msgbody)
	if not service then
		service = CMD.service
	end

    if not msgbody or not gamelist[msgbody.gamename] then
        return {retcode = EErrCode.ERR_INVALID_PARAMS, retstr = "无效的参数"}
    end

    local curscore = msgbody.score or 0
    local tablename = "rs_" .. msgbody.gamename .. "result"
    local result = cluster.call("datanode", ".router", "select_rk", rid, tablename)
	if result[1] ~= 0 then 
        local maxscore = result[2][rid].maxscore
        if curscore > maxscore then
            cluster.send("datanode", ".router", "update_rk", rid, tablename, 0, {maxscore = curscore})
        end
        return { gamename = msgbody.gamename}
    end

    return {retcode = -1, retstr = "上传分数失败"}
end

return CMD
